package cn.web.demo.service.impl;

import cn.web.demo.mapper.CourseOrderMapper;
import cn.web.demo.model.CourseOrder;
import cn.web.demo.model.Income;
import cn.web.demo.model.PageResult;
import cn.web.demo.service.CouseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class CouseOrderServiceImpl implements CouseOrderService {

    @Autowired
    CourseOrderMapper CourseOrderMapper;


    @Override
    public PageResult<CourseOrder> findPageResult(CourseOrder condition, int page, int pageSize) {
        //定义一个Map-参数先不放在map,后面再处理
        Map<String,Object> params = new HashMap<>();
        params.put("condition",condition);
        params.put("start", (page-1)*pageSize);
        params.put("limit", pageSize);
        //定义结果
        PageResult<CourseOrder> result = new PageResult<>();
        result.setCode(0);
        result.setCount(CourseOrderMapper.findCountByMap(params));
        result.setData(CourseOrderMapper.findListByMap(params));
        return result;
    }

    public void save(CourseOrder condition){
        CourseOrderMapper.inset(condition);
    }

    public CourseOrder findById(String id){
        return  CourseOrderMapper.findById(id);
    }

    public void DelectById(String id){
         CourseOrderMapper.DelectById(id);
    }

    public void update(CourseOrder condition){
        CourseOrderMapper.update(condition);
    }

    public List<Income> incomejson(){
        return CourseOrderMapper.incomejson();
    }
}
